home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / GAMES / RHFT / Docs / !StrongHlp / Utilities / CleanCopy (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1995-05-25  |  4KB  |  172 lines

  1.   >CleanCopy
  2.  We dummy-define these variables so that PROC_Error will know them
  3.  if we should crash before they are actually defined
  4.   del% = 
  5.   A$   = ""
  6.   B$   = ""
  7. _Error
  8.  wrk% 255, wrk2% 255
  9.  "Hourglass_On"
  10.  Find parameters
  11.  "OS_GetEnv" 
  12.  env$
  13.   A$ = 
  14. _GetArg(env$,2)
  15.   B$ = 
  16. _GetArg(env$,3)
  17.  PRINT "env = ";env$
  18.  PRINT "A = ";A$
  19.  PRINT "B = ";B$
  20.  A$ = "" 
  21.  -1,"Needs Manual name"
  22.  B$ = "" 
  23. .    
  24.  First test whether Wimp$Scrap exists
  25. 8    
  26.  "XOS_ReadVarVal","Wimp$Scrap",,-1,0,0 
  27.  ,,R2%
  28.  1    
  29.  R2%>=0 
  30.  0,"Wimp$Scrap isn't defined"
  31. "#    
  32.  Remove any old Wimp$Scrap
  33. #,    
  34.  "OS_File",17,"<Wimp$Scrap>" 
  35. $,    
  36.  R0% <> 0 
  37.  "Delete <Wimp$Scrap>"
  38.     B$ = A$
  39.     A$ = "<Wimp$Scrap>"
  40.  "Rename "+B$+" "+A$
  41.     del% = 
  42.     del% = 
  43.  We create the new "Manual"
  44.   A% = 
  45. _DirSize(A$)
  46.  "StrongCreate "+B$+" "+
  47.  Now recursively copy everything
  48. _CopyDir(A$,B$)
  49.  If we used Wimp$Scrap, we now delete it.
  50.  del% 
  51.  "Delete "+A$
  52.  Force Close of new version
  53.  (So that we don't have to quit !StrongHelp (which closes all) to be safe)
  54.  "Rename "+B$+" "+B$
  55.  "Hourglass_Off"
  56. _CopyDir(From$,To$)
  57.  offset%,read%,x%,A%,F$,T$,S%,strlen%
  58.   offset% = 0
  59. LG    
  60.  "OS_GBPB",10,From$,wrk%,1,offset%,255,"*" 
  61.  ,,,read%,offset%
  62.  read% > 0 
  63.       x% = wrk%
  64.       
  65.  A% = 1 
  66.  read%
  67. P%        strlen% = 
  68. _StrLen(x%+20)
  69. Q!        ?(x%+20+strlen%) = 13
  70. S'        F$ = From$ + "." + $(x%+20)
  71. T'        T$ = To$   + "." + $(x%+20)
  72.         
  73.  x%!16 
  74. V&          
  75.  1 : 
  76.  PRINT "Copy ";F$
  77. W3                   
  78.  "OS_FSControl",26,F$,T$,0
  79. X&          
  80.  2 : S% = 
  81. _DirSize(F$)
  82. Y.                   
  83.  PRINT "Create ";T$,S%
  84. Z,                   
  85.  "Cdir "+T$+" "+
  86. ['                   
  87. _CopyDir(F$,T$)
  88.         
  89. ^-        x%     += ((strlen%+4) 
  90.  3) + 20
  91.       
  92. `        
  93.  offset% = -1
  94. _DirSize(dir$)
  95.  tot%,offset%,strlen%,A%,x%
  96.  This routine calculates the size of all the entries in a directory,
  97.  and all heading info for the dir.
  98.  The size of heading info is
  99.     4 (offset into dir of 1st unused pos)
  100.  The size of one entry is
  101.    24 (offset in image, load, exec, size, flags, compressed size)
  102.  + word aligned length of name (incl \0)
  103.  (The 'compressed size' is there for possible future use)
  104.   tot% = 4
  105.   offset% = 0
  106. uI    
  107.  "OS_GBPB",10,dir$,wrk2%,255,offset%,255,"*" 
  108.  ,,,read%,offset%
  109.  read% > 0 
  110.       x% = wrk2%
  111.       
  112.  A% = 1 
  113.  read%
  114. y2        strlen% = ( 
  115. _StrLen(x%+20) + 4 ) 
  116. z"        tot%   += strlen% + 24
  117. {"        x%     += strlen% + 20
  118.       
  119. }        
  120.  offset% = -1
  121. = tot%
  122. _StrLen(A%)
  123.   L% = A%
  124.  ?A% >= 32
  125.     A% += 1
  126. = A% - L%
  127. _GetArg(arg$,no%)
  128.  a%,b%,x%
  129.  Find start of the given part
  130.   a% = 1
  131.   x% = 0
  132.     a% = 
  133. arg$," ",a%)
  134.  a% = 0 
  135.       = ""
  136.         
  137.     a% += 1
  138. arg$,a%,1) = " ")
  139.       a% += 1
  140.         
  141. 1    
  142. arg$,a%,1) = "-" 
  143. arg$,a%,1) = "@" 
  144.       no% +=1
  145.         
  146.     x% += 1
  147.  x% >= no%
  148.  Find end of the given part
  149.   b% = 
  150. arg$," ",a%)
  151.  b% = 0 
  152.     = 
  153. arg$,a%)
  154.     = 
  155. arg$,a%,b%-a%)
  156. _Error
  157.  "Hourglass_Off"
  158.  If we have renamed original file to Wimp$Scrap, then we should move
  159.  it back..
  160.  del% 
  161. .    
  162.  1st delete new file (if it exists..)
  163.      
  164.  "OS_File",17,B$ 
  165. #    
  166.  R0% <> 0 
  167.  "Delete "+B$
  168. !    
  169.  Move original file back
  170.  "Rename "+A$+" "+B$
  171. $;" at ";
  172.